﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LRT.Syndication.Components;
using Dapper;

namespace LRT.Syndication.Data
{
    internal partial class DataProvider
    {
		#region Channel 
		///<summary>
		///插入 频道
		///</summary>
		public void InsertChannel(Channel value)
        {
            const string sql = @"INSERT INTO [Syndication].[Channel] ([Title],[Link],[Description],[Category],[Cloud],[Copyright],[Docs],[Generator],[Image],[Language],[LastBuildDate],[ManagingEditor],[PubDate],[Rating],[SkipDays],[SkipHours],[TextInput],[Ttl],[WebMaster])VALUES(@Title,@Link,@Description,@Category,@Cloud,@Copyright,@Docs,@Generator,@Image,@Language,@LastBuildDate,@ManagingEditor,@PubDate,@Rating,@SkipDays,@SkipHours,@TextInput,@Ttl,@WebMaster)";
            using (var connection = GetDbConnection())
            {
                connection.Execute(sql, value);
            }
        }

		///<summary>
		///更新 频道
		///</summary>
        public void UpdateChannel(Channel value)
        {

            const string sql = @"UPDATE  [Syndication].[Channel] SET [Title]=@Title,[Link]=@Link,[Description]=@Description,[Category]=@Category,[Cloud]=@Cloud,[Copyright]=@Copyright,[Docs]=@Docs,[Generator]=@Generator,[Image]=@Image,[Language]=@Language,[LastBuildDate]=@LastBuildDate,[ManagingEditor]=@ManagingEditor,[PubDate]=@PubDate,[Rating]=@Rating,[SkipDays]=@SkipDays,[SkipHours]=@SkipHours,[TextInput]=@TextInput,[Ttl]=@Ttl,[WebMaster]=@WebMaster WHERE [ID]=@ID ";
            using (var connection = GetDbConnection())
            {
                connection.Execute(sql, value);
            }
        }
		
		///<summary>
		///查找 频道
		///</summary>
        public Channel FindChannel(int id)
        {
            const string sql = @"SELECT * FROM  [Syndication].[Channel]  WHERE [ID]=@ID";
            using (var connection = GetDbConnection())
            {
                return connection.Query<Channel>(sql, new { ID = id }).SingleOrDefault();
            }
        }

		///<summary>
		///删除 频道
		///</summary>
        public void DeleteChannel(int id)
        {
            const string sql = @"DELETE FROM  [Syndication].[Channel]  WHERE [ID]=@ID ";
            using (var connection = GetDbConnection())
            {
                connection.Execute(sql, new { ID = id });
            }
        }
		
		/// <summary>
        ///  分页查询 频道
        /// </summary>
		public IEnumerable<Channel> QueryChannel(out int total, int pageIndex, int pageSize, object param)
		{
			const string sql = @"SELECT * FROM  [Syndication].[Channel]"; //  WHERE cdt ...
			const string sort = "ID";
			return GetPagedList<Channel>(out total, pageIndex, pageSize, sql, sort, param);

		}
		
		/// <summary>
        ///  查询 频道
        /// </summary>
		public IEnumerable<Channel> QueryChannel(object param)
		{
			const string sql = @"SELECT * FROM  [Syndication].[Channel]"; //  WHERE cdt ...
			const string sort = "ID";
			return GetQueryList<Channel>(sql, sort, param);	
		}

		#endregion
	}
}
